<?php

namespace app\index\controller;

use app\index\model\HelpTab as HelpTabModal;
use app\index\model\Help as HelpModal;
use app\BaseController;
class Help extends BaseController
{
    protected $middleware = [
        'Auth' => ['except' => ['list', 'tab', 'detail']],
    ];

    public function tab()
    {
        $sql = new HelpTabModal();
        $list = $sql ->order('sort desc')
            ->order('create_at desc')->select();
        return result()->success($list);
    }
    public function list()
    {
        $params = $this->request->post(['hor', 'tab_id']);
        $sql = new HelpModal();
        $whereArr = [];
        if(isset($params['hor']) && $params['hor']) {
            $whereArr[] = ['hor', '=',1];
        }
        if(isset($params['tab_id']) && $params['tab_id']) {
            $whereArr[] = ['tab_id', '=',$params['tab_id']];
        }
        $list = $sql->where($whereArr)->order('sort desc')
            ->order('create_at desc')->select();
        return result()->success($list);
    }

    public function detail()
    {
        $params = $this->request->post(['id']);
        $sql = new HelpModal();
        $info = $sql->find($params['id']);
        return result()->success($info);
    }
}